/**
 * Created by 25047 on 2018/5/27.
 */
class FileUploadAdapter {
    constructor(loader) {
        this.loader = loader;
    }

    upload() {
        const data = new FormData();
        const config = {
            headers: {'content-type': 'multipart/form-data'}
        };

        data.append('file', this.loader.file);

        return new Promise((resolve, reject) => {
            if (this.loader.file.size > 400 * 1024) {
                reject('本站暂不支持上传大小超过400k的图片，请将图片体积压缩小于400K后再上传');
            }
            axios.post('/upload_ckeditor', data, config).then(response => {
                if (!response.data.status) {
                    reject(response.data.msg);
                    return false;
                }
                resolve({
                    default: response.data.url
                })
            }).catch(error => {
                reject(error)
                alert(error.mesage);
            });
        });
    }

    abort() {
        //
    }
}